import re


def set_text(file, data):
    with open(file, 'w') as f:
        f.write(data)


def get_text(file):
    with open(file, 'r') as f:
        content = f.read()
        return content


def MyIter(txt_str):
    yield re.findall(r'[0-9]+', txt_str)


s = "123asd456aff"
set_text('test.txt', s)
txt = get_text('test.txt')

my_iter = MyIter(txt)
for i in my_iter:
    print(i)

